package com.send.service;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.send.api.IMailService;
import com.send.api.IQueue;
import com.send.config.BaseSend;
import com.send.queue.SendQueue;

/**
 * Created by Jon on 2018/1/4.
 */
@Service
public class QueueServiceImpl implements IQueue {

    @Autowired
    private IMailService iMailService;//执行者

    /*@Value("${spring.mail.username}")*/
    public String USER_NAME;//发送者

    static {
        System.setProperty("mail.mime.splitlongparameters","false");
    }

    @Override
    public boolean sendQueue(BaseSend t) throws Exception {
        SendQueue.getMailQueue().produce(t);
        return true;
    }

   /* @Override
    public void send(MSendEmailVo mail) throws Exception {
        System.out.print("发送成功:" + mail);
        *//*redisService.set("ddsw","gggggggg");*//*
    }*/

   /* *//**
     * 第一版发送邮件暂时从消费端获取邮件的相关参数,第二版考虑从服务端配置里取
     * @param mailInfo
     * @return
     * @throws Exception
     *//*
    @Override
    public boolean sendHtml(EmailConfig mailInfo) throws Exception {
        try {
            MailUtil mailUtil = new MailUtil();
            JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
            MimeMessage testMessage = javaMailSender.createMimeMessage();
            MimeMessageHelper testMessageHelper = new MimeMessageHelper(testMessage, "UTF-8");
            Properties prop = new Properties();
            // 将这个参数设为true，让服务器进行认证,认证用户名和密码是否正确
            prop.put("mail.smtp.auth", "true");
            prop.put("mail.host", mailInfo.getMailServerHost());
            // 超时时间
            prop.put("mail.smtp.timeout", "25000");
            // 添加验证
            javaMailSender.setJavaMailProperties(prop);
            javaMailSender.setUsername(mailInfo.getUserName().trim());
            javaMailSender.setPassword(mailInfo.getPassword().trim());
            testMessageHelper.setFrom(new InternetAddress(mailInfo.getFromAddress(), mailInfo.getNickname()));
            testMessageHelper.setTo(mailInfo.getToAddress().trim());
            testMessageHelper.setSubject(mailInfo.getSubject());
            testMessageHelper.setText(mailInfo.getContent(), true);
            mailUtil.startHtml(javaMailSender,testMessage);
            *//*javaMailSender.send(testMessage);*//*
        } catch (Exception mex) {
            throw new I2pException("Error Sending mail", mex);
        }
        return true;


    }*/

    /*@Override
    public void sendFreemarker(MSendEmailVo mail) throws Exception {

    }

    @Override
    public void sendThymeleaf(MSendEmailVo mail) throws Exception {

    }

    @Override
    public void sendQueue(MSendEmailVo mail) throws Exception {

    }

    @Override
    public void sendRedisQueue(MSendEmailVo mail) throws Exception {

    }
*/

}
